# $Id: PKGBUILD 88141 2013-04-12 12:11:57Z seblu $
# Maintainer: Sébastien Luttringer

pkgname=quagga
pkgver=0.99.22.1
pkgrel=1
pkgdesc='BGP/OSPF/ISIS/RIP/RIPNG routing daemon suite'
arch=('i686' 'x86_64')
url='http://www.quagga.net'
license=('GPL2')
depends=('libcap' 'libnl' 'net-snmp' 'readline' 'ncurses')
options=('!libtool' '!buildflags')
install=quagga.install
source=("http://download.savannah.gnu.org/releases/$pkgname/$pkgname-$pkgver.tar.gz"
        'babeld.service'
        'bgpd.service'
        'isisd.service'
        'ospf6d.service'
        'ospfd.service'
        'ripd.service'
        'ripngd.service'
        'zebra.service')
md5sums=('d9ab848661720d6da2551c7a4a19c731'
         '87bf4ae8aca3b3cf70e3986bc669aa78'
         '9b14110bed4982baa801808db6ac9135'
         'b685b5c12637cb963e1fb78ecd926e14'
         '1fee8cdf03f87b9bb129948058246c88'
         '4d95a4af1ddb4ae21b867bebbedc77d5'
         '7e33c2a2e1c12309ba28d75a34294ed0'
         '6c682c0cd06c109bc10d29c1d9af3e38'
         '18964536b7ed012aa5b22f2fa9fb3e87')

prepare() {
  cd $pkgname-$pkgver
  shopt -s nullglob
  for _p in "$srcdir"/*.patch; do
    msg2 "Applying ${_p##*/}"
    patch -p 1 -i "$_p"
  done
}

build() {
  cd $pkgname-$pkgver
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc/quagga \
    --localstatedir=/run/quagga \
    --enable-exampledir=/usr/share/doc/quagga/examples \
    --enable-vtysh \
    --enable-isisd \
    --enable-isis-topology \
    --enable-netlink \
    --enable-snmp \
    --enable-tcp-zebra \
    --enable-irdp \
    --enable-pcreposix \
    --enable-multipath=64 \
    --enable-user=quagga \
    --enable-group=quagga \
    --enable-configfile-mask=0640 \
    --enable-logfile-mask=0640
  make
}

package() {
  # upstream install
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install

  # logrotate stuff
  install -D -m 644 redhat/$pkgname.logrotate "$pkgdir/etc/logrotate.d/$pkgname"
  sed -ri 's,/var/run/quagga,/run/quagga,g' "$pkgdir/etc/logrotate.d/$pkgname"

  # systemd
  cd "$srcdir"
  for _d in zebra ripd ripngd bgpd ospfd ospf6d isisd babeld; do
    install -D -m 644 $_d.service "$pkgdir/usr/lib/systemd/system/$_d.service"
  done
  install -D -m 644 /dev/null "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
  echo "d /run/$pkgname 0750 $pkgname $pkgname" > "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
}

# vim:set ts=2 sw=2 et:
